package com.csun.cmny.provider.web.frontend;

import com.alibaba.fastjson.JSON;
import com.csun.cmny.provider.config.ueditor.ActionEnter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-06-04 10:06
 * @Description: the class ueditor controller
 */
@Slf4j
@RestController
@RequestMapping(value = "/api/ueditor", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class UeditorController {

    @RequestMapping(value = "/exec")
    public Object exec(HttpServletRequest request) throws UnsupportedEncodingException {
        request.setCharacterEncoding("utf-8");
        String rootPath = request.getRealPath("/");
        String message = new ActionEnter(request, rootPath).exec();

        //log.info("-----chisj:message = {}", message);

        return JSON.parseObject(message);
    }

}
